package org.example.game.history;

import java.util.HashMap;

/**
 * @Description: TODO
 * @Author wyatt
 * @Data 2024/05/26 11:13
 */
@Deprecated
public class Solution100306 {

    public static void main(String[] args) {

        System.out.println(10*10*10*10*10*10*10*10*10  + 7);
        Solution100306 solution100306 = new Solution100306();
        int[] nums = new int[]{3,-3,3,-1,-3,2,-1};
        int[][] queries = new int[][]{{2,-1},{2,3},{4,3},{2,1},{4,3},{6,-3},{1,0},{2,3}};
        System.out.println(solution100306.maximumSumSubsequence(nums, queries));
    }

    public int maximumSumSubsequence(int[] nums, int[][] queries) {

        int res = 0;
        int sum1 = 0;
        int sum2 = 0;
        HashMap<Integer, Integer> indexValueMap1 = new HashMap<>();
        HashMap<Integer, Integer> indexValueMap2 = new HashMap<>();

        for(int i=0;i<nums.length;i++){
            if(i % 2 == 0){
                if(nums[i] > 0){
                    sum2 += nums[i];
                    if(sum2 > 1000000007){
                        sum2 = sum2%1000000007;
                    }
                    indexValueMap2.put(i, nums[i]);
                    indexValueMap1.put(i, 0);
                }else {
                    indexValueMap2.put(i, 0);
                }
            }else {
                if(nums[i] > 0){
                    sum1 += nums[i];
                    if(sum1 > 1000000007){
                        sum1 = sum1%1000000007;
                    }
                    indexValueMap1.put(i, nums[i]);
                    indexValueMap2.put(i, 0);
                }else {
                    indexValueMap1.put(i, 0);
                }
            }
        }

        for(int j=0;j<queries.length;j++){
            int index = queries[j][0];
            int value = queries[j][1];

            if(index % 2 == 0){
                if(value < 0){
                    if(indexValueMap2.get(index) > 0){
                        sum2 = sum2 - indexValueMap2.get(index);
                    }
                    indexValueMap2.put(index, 0);
                }else {
                    sum2 = sum2 + value;
                    if(sum2 > 1000000007){
                        sum2 = sum2%1000000007;
                    }
                    if(indexValueMap2.get(index) > 0){
                        sum2 = sum2 - indexValueMap2.get(index);
                    }
                    indexValueMap2.put(index, value);
                }
            }else {
                if(value < 0){
                    if(indexValueMap1.get(index) > 0){
                        sum1 = sum1 - indexValueMap1.get(index);
                    }
                    indexValueMap1.put(index, 0);
                }else {
                    sum1 = sum1 + value;
                    if(sum1 > 1000000007){
                        sum1 = sum1%1000000007;
                    }
                    if(indexValueMap1.get(index) > 0){
                        sum1 = sum1 - indexValueMap1.get(index);
                    }
                    indexValueMap1.put(index, value);
                }
            }

            res += Math.max(sum1, sum2);

            if(res > 1000000007){
                res = res%1000000007;
            }
        }

        return res;

    }

}
